#pragma once
#include <iostream>
#include <string>
#include <unistd.h>



class Task
{
public:
    Task()
    {
    }
    Task(int x, int y, char op)
        : x_(x), y_(y), op_(op), result_(0), exitcode_(0)
    {
    }
    void operator()() // 仿函数
    {
        switch (op_)
        {
        case '+':
            result_ = x_ + y_;
            break;
        case '-':
            result_ = x_ - y_;
            break;
        case '*':
            result_ = x_ * y_;
            break;
        case '/':
        {
            if (y_ == 0)
                exitcode_ = -1;
            else
                result_ = x_ / y_;
        }
        break;
        case '%':
        {
            if (y_ == 0)
                exitcode_ = -2;
            else
                result_ = x_ % y_;
        }
        break;
        default:
            break;
        }
        usleep(100000); //生产任务可能要花时间 但是消费也是需要时间的
    }
    std::string formatArg()
    {
        return std::to_string(x_) + op_ + std::to_string(y_) + " =";
    }
    std::string formatRes()
    {
        return std::to_string(result_) + "(" + std::to_string(exitcode_) + ")";
    }
    ~Task()
    {}

private:
    int x_;
    int y_;
    char op_;
    int result_;
    int exitcode_;
};